<?php
namespace app\admin\controller;


use app\admin\model\StaffOrder;
use think\Request;

class StaffServices extends Base
{
    protected function _initialize(){
        $this->menuLoad();
    }
    public function index(){
        return $this->fetch('public/help');
    }

    public function staffServicesList(){
        $staffServices = new \app\admin\model\StaffServices();
        $where['id'] = ['neq',0];
        $rs = $staffServices->getPageAll($where);
        $this->assign('rs',$rs);
        return $this->fetch();
    }

    public function addStaffServices(Request $request){
        if($request->post()){
            $data = $request->post();
            $staffServices = new \app\admin\model\StaffServices();
            $rs = $staffServices->add($data);
            if($rs){
                return $this->success('添加成功');
            }else{
                return $this->error('添加失败');
            }
        }
        return $this->fetch();
    }

    public function editStaffServices(Request $request){
        $staffServices = new \app\admin\model\StaffServices();
        if($request->post()){
            $data = $request->post();
            $where['id'] = $data['id'];
            unset($data['id']);
            $rs = $staffServices->edit($where,$data);
            if($rs){
                return $this->success('修改成功');
            }
            return $this->error('修改失败');
        }
        $data = $request->get();
        $rs = $staffServices->getOne($data);
        $this->assign('rs',$rs);
        return $this->fetch();
    }

    public function staffOrderList(Request $request){
        $data = $request->get();
        $staffOrder = new StaffOrder();
        $where['staff_id'] = $data['staff_id'];
        $rs = $staffOrder->getPageAll($where);
        $this->assign('rs',$rs);
        return $this->fetch();
    }

    public function editStaffOrder(Request $request){
        $staffOrder = new StaffOrder();
        if($request->get()){
            $data = $request->get();
            $were['id'] = $data['staff_id'];
            $rs = $staffOrder->getOne($were);
            $this->assign('rs',$rs);
            return $this->fetch();
        }else{
            $data = $request->post();
            $where['id'] = $data['id'];
            unset($data['id']);
            $rs = $staffOrder->edit($where,$data);
            if($rs){
                return $this->success('修改成功');
            }
            return $this->error('修改失败');
        }
    }
}